package com.xhdd.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;

@Data
@ApiModel
public class Retn<T> {
    @ApiModelProperty("响应码，0：正常、非0：异常")
    private int code;
    @ApiModelProperty("错误信息")
    private String err;
    @ApiModelProperty("响应数据")
    private T data;

    public Retn(int code, String err, T data) {
        this.code = code;
        this.err = err;
        this.data = data;
    }

    public static <T> Retn<T> ok(Object data) {
        return new Retn(0, null, data);
    }
    public Retn(Object k,Object v) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put(k,v);
        this.data = (T) map;
    }

    public static <T> Retn<T> err(int code, String err) {
        return new Retn(code, err, null);
    }

    public static <T> Retn<T> err(int code, String err,T data) {
        return new Retn(code, err, data);
    }
}
